package cmd

import (
	"github.com/spf13/cobra"
	"longmen/server/config/global"
	api2 "longmen/server/internal/services/nami/api"
	"longmen/server/internal/services/nami/api/v5/sports/basketball"
	"longmen/server/internal/services/nami/api/v5/sports/cricket"
	"longmen/server/internal/services/nami/api/v5/sports/football"
	"longmen/server/internal/services/nami/config"
)

var initCli = &cobra.Command{
	Use:   "init",
	Short: "初始化数据",
	Long:  "初始化数据",
	Run: func(cmd *cobra.Command, args []string) {
		var initFaces []api2.SyncInitInterface
		if config.NamiCricketEnabled() {
			initFaces = append(initFaces, cricket.InitCricket{})
		}
		if config.NamiFootballEnabled() {
			initFaces = append(initFaces, football.InitFootBall{})
		}
		if config.NamiBasketballEnabled() {
			initFaces = append(initFaces, basketball.InitBasketBall{})
		}

		for i := 0; i < len(initFaces); i++ {
			initFaces[i].SyncCompetitionById()
			initFaces[i].SyncTeamById()
		}

		//初始化的部分
		var syncFaces []api2.SyncInterface
		if config.NamiCricketEnabled() {
			syncFaces = append(syncFaces, cricket.Cricket{})
		}
		if config.NamiFootballEnabled() {
			syncFaces = append(syncFaces, football.Football{})
		}
		if config.NamiBasketballEnabled() {
			syncFaces = append(syncFaces, basketball.BasketBall{})
		}

		// 循环初始化所有的同步行为
		for i := 0; i < len(syncFaces); i++ {
			syncFaces[i].SyncCountry()
			syncFaces[i].SyncCategory()
			syncFaces[i].SyncTeam()
			syncFaces[i].SyncCompetition()
			syncFaces[i].SyncMatch()
			syncFaces[i].SyncFutureMatch()
			syncFaces[i].SyncLive()
			syncFaces[i].SyncRecent()
			syncFaces[i].SyncDelete()
		}

	},
	PreRun: func(cmd *cobra.Command, args []string) {
		global.Initialize(configFile)
		config.InitConfig()
	},
	PostRun: func(cmd *cobra.Command, args []string) {

	},
}
